package classification.elemListRepr;

import java.util.HashMap;

/**
 * The XMLElement is used to record the information in each element in xml
 * document, and it will be accessed when classification process
 * 
 * @author eDisOn
 * 
 */
public class XMLElement
{
    private String                  elemName       = "";
    private String                  elemLabel      = "";
    private String                  text           = "";
    private int                     vocNum         = 0;
    private int                     elementLevel   = 0;
    private int                     frequency      = 0;                            // 用于记录该Element在所有xml文档中出现的次数
    private HashMap<String, Double> vocubularyList = new HashMap<String, Double>();

    public XMLElement(String initElemName)
    {
        this.elemName = initElemName;
    }

    public XMLElement(String initElemName, int initFreq)
    {
        this.elemName = initElemName;
        this.frequency = initFreq;
    }

    public XMLElement(XMLElement elem)
    {
        this.elemName = elem.getXMLElemName();
    }

    public String getXMLElemName()
    {
        return this.elemName;
    }

    public void setFrequency(int newFrequency)
    {
        this.frequency = newFrequency;
    }

    public void setVocNum(int vocNum)
    {
        this.vocNum = vocNum;
    }

    public int getVocNum()
    {
        return this.vocNum;
    }

    public void increaseFreq()
    {
        this.frequency++;
    }

    public int getFrequency()
    {
        return this.frequency;
    }

    public void appendText(String append)
    {
        this.text += append;
        if (!append.equals(""))
        {
            this.text += " ";
        }
    }

    public void replaceText(String newText)
    {
        this.text = newText;
    }

    public String getText()
    {
        return this.text;
    }

    public void addVocabulary(String voc)
    {
        if (!this.vocubularyList.containsKey(voc))
        {
            this.vocubularyList.put(voc, 1.0);
        }
        else
        {
            double value = this.vocubularyList.get(voc);
            this.vocubularyList.put(voc, value + 1);
        }
    }

    public void setVocabularyList(HashMap<String, Double> newVocList)
    {
        this.vocubularyList = newVocList;
    }

    public HashMap<String, Double> getVocabularyList()
    {
        return this.vocubularyList;
    }
}
